package HashMapStudey;

import ArrayListShiLi.Student;

import java.util.*;

public class HashiMapStudy1 {
    public static void main(String[] args) {
        //哈希表
        HashSet<Student>students=new HashSet<>();
        students.add(new Student(1,"aa",44.4));
        students.add(new Student(2,"bb",44.4));
        students.add(new Student(3,"cc",44.4));
        //foreach
        for (Student stu:students)
        {
            System.out.println("stu = " + stu);
        }
        //hasMap测试//键必须是对象即包装类
        HashMap<String,Student>stringStudentHashMap=new HashMap<>();
        stringStudentHashMap.put("11",new Student(1,"aa",44.4));
        stringStudentHashMap.put("22",new Student(2,"bb",44.4));
        stringStudentHashMap.put("33",new Student(3,"cc",44.4));
        //遍历 迭代器
        Set<Map.Entry<String,Student>>entries=stringStudentHashMap.entrySet();
        Iterator<Map.Entry<String, Student>> iterator = entries.iterator();
        while (iterator.hasNext()){
            Map.Entry<String, Student> next = iterator.next();
            System.out.println("next.getKey() = " + next.getKey());
            System.out.println("next.getValue() = " + next.getValue());
            System.out.println("--------------------------");
        }
        //高阶遍历
        System.out.println("----------------------------");
        for (Map.Entry<String,Student> entry:stringStudentHashMap.entrySet()){
            System.out.println("entry.getKey() = " + entry.getKey());
            System.out.println("entry.getValue() = " + entry.getValue());
        }
        //简单遍历
        System.out.println("-----------------------------------");
        for (String key:stringStudentHashMap.keySet()) {
            System.out.println("key = " + key);
            System.out.println("stringStudentHashMap.get(key) = "
                    + stringStudentHashMap.get(key));
        }
    }

}
